package amushen.two.html;

import java.util.ArrayList;

public abstract class BaseContainer extends BaseComponent implements IHTMLContainer {

	private ArrayList child=new ArrayList();
	
	public abstract String getTagName();

	public void addChild(IHTMLComponent child) {
		this.child.add(child);
	}

	public IHTMLComponent getChild(int index) {		
		return (IHTMLComponent)this.child.get(index);
	}

	public int getChildrenCount() {		
		return this.child.size();
	}

	public void insertChild(IHTMLComponent child, int index) {
		this.child.add(index,child);
	}

	public void removeChild(int index) {
		this.child.remove(index);
	}
	
	public void clear() {
		this.child.clear();
	}
	
	public void setChild(int index, IHTMLComponent child) {
		this.child.set(index, child);
	}	
	
	public String getContent() {
		StringBuffer sb=new StringBuffer();
		for(int i=0;i<child.size();i++){
			IHTMLComponent c=(IHTMLComponent)child.get(i);
			sb.append(c.toString());
		}
		if(super.getContent()!=null)
			sb.append(super.getContent());
		return sb.toString();
	}
}
